package com.yochi.pictureseditor.effects.effectsimpl;

import com.yochi.pictureseditor.effects.EffectParametrized;
import com.yochi.pictureseditor.effects.converters.ContrastConverter;
import com.yochi.pictureseditor.exceptions.NullImageException;
import com.yochi.pictureseditor.images.Image;
import com.yochi.pictureseditor.images.ImageImpl;

public class EffectAdjustContrast extends EffectParametrized {
	
	  //////////////////
	 // CONSTRUCTORS //
	//////////////////

	public EffectAdjustContrast(Image img) {
		super(img, "Contrast level", 0, 256);
		setPreParametrized(false);
	}
	
	public EffectAdjustContrast(Image img, int param) {
		super(img, "Contrast level", 0, 256);
		getParameter().setValue(new ContrastConverter().convert(param)); // rescale parameter value
		setPreParametrized(true);
	}
	
	  ////////////
	 // NATIVE //
	////////////
	
	static {
		System.loadLibrary("pictureseditor");
	}
	
	public native ImageImpl process(Image image, double parameter);
	
	
	  ////////////
	 // PUBLIC //
	////////////
	
	@Override
	public Image apply() throws NullImageException {
		if(getImage()==null) throw new NullImageException("load an image before applying effect");
		Image result = process();
		setResult(result);
		return result;
	}
	
	
	  ///////////////
	 // PROTECTED //
	///////////////

	@Override
	protected Image process() {
		return process(getImage(), getParameter().getValue());
	}
	
	@Override
	public String toString() {
		return "[EffectAdjustContrast]";
	}

}
